package com.modules.system.service.impl;

import com.common.base.BaseServiceImpl;
import com.modules.system.entity.SysMenuEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.modules.system.dao.SysRoleDao;
import com.modules.system.entity.SysRoleEntity;
import com.modules.system.service.SysRoleMenuService;
import com.modules.system.service.SysRoleService;
import java.util.Date;
import java.util.List;


/**
 * 角色
 * 
 */
@Service("sysRoleService")
public class SysRoleServiceImpl  extends BaseServiceImpl<SysRoleEntity> implements SysRoleService {
	@Autowired
	private SysRoleDao sysRoleDao;
	@Autowired
	private SysRoleMenuService sysRoleMenuService;

	@Autowired
	private void setBaseMapper(){
		super.setBaseMapper(sysRoleDao);
	}

	@Override
	@Transactional
	public void save(SysRoleEntity role) {
		role.setCreateTime(new Date());
		sysRoleDao.insert(role);
		//保存角色与菜单关系
		sysRoleMenuService.saveOrUpdate(role.getRoleId(), role.getMenuIdList());
	}

	@Override
	@Transactional
	public void update(SysRoleEntity role) {
		role.setCreateTime(new Date());
		sysRoleDao.updateByPrimaryKey(role);
		//更新角色与菜单关系
		sysRoleMenuService.saveOrUpdate(role.getRoleId(), role.getMenuIdList());

	}

	@Override
	@Transactional
	public void deleteBatch(Long[] roleIds) {
		sysRoleDao.deleteBatch(roleIds);
	}

}
